package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsAddress;
import com.qf.service.DtsAddressService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lixu
 */
@RestController
@RequestMapping("/admin/address")
@CrossOrigin
public class AddressController {

    @Autowired
    private DtsAddressService dtsAddressService;


    /**
     * ####  收货地址
     *
     * ##### 2.1.3.1. 收货地址列表
     *
     * - 接口地址 : http://localhost:8083/admin/address/list?page=1&limit=20&sort=add_time&order=desc
     *
     * - 下行数据 :
     */
    @RequiresPermissionsDesc(menu = {"用户管理","收货地址"},button = "查询")
    @RequiresPermissions(value = "admin:address:list")
    @GetMapping("/list")
    public Object list(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "20") Integer limit,
                       String sort,String order,String name,Integer userId){
        IPage<DtsAddress> iPage = dtsAddressService.findListByQuery(page,limit,sort,order,name,userId);
        Map data = new HashMap<>();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return ResponseUtil.ok(data);
    }
}
